﻿using System.Text.Json;
using System.Text.Json.Serialization;

namespace Knowledge.EF.Back.Helpers
{
    public class JsonConvertHelper
    {
        /// <summary>
        /// 封装后的反序列化方法
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="sj">形参</param>
        /// <returns></returns>
        public static T Deserialize<T>(string sj)
        {
            var options = new JsonSerializerOptions
            {
                NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString,
                // 設定在做序列化/反序列化時，尊重名稱大小寫
                PropertyNameCaseInsensitive = true

            };
            var a = JsonSerializer.Deserialize<T>(sj, options);
            return a;
        }
    }
}
